package com.ternnetwork.core.notice.entity;


import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.ternnetwork.commons.utils.JsonDateSerializer;
import com.ternnetwork.persistence.entity.VersionEntity;
import lombok.Data;

import javax.persistence.*;
import java.util.Date;

@Entity
@Table(name="AVO_NOTICE")
@JsonIgnoreProperties(value={"handler","hibernateLazyInitializer"})
@Data
public class Notice extends VersionEntity {

    @Id
    @Column(name="ID",nullable=false)
    @GeneratedValue(strategy = GenerationType.TABLE,generator="id_gen")
    @TableGenerator(name = "id_gen",pkColumnValue="AVO_NOTICE_ID",table="AVO_ID_GENERATOR", pkColumnName="GEN_NAME",valueColumnName="GEN_VALUE",allocationSize=1)
    private long id;


    @Column(name="title",nullable=false)
    private String title;

    @Column(name="content")@Lob@Basic(fetch = FetchType.LAZY)
    private String content;

    @ManyToOne
    @JoinColumn(name="category_id",nullable=true)
    private NoticeCategory category;


    @Column(name="published")
    private Boolean published=Boolean.FALSE;

    @Column(name="published_code",nullable=true)
    private String publishedCode;

    @Column(name="published_time",nullable=true)
    @Temporal(TemporalType.TIMESTAMP)
    private Date publishedTime;

    @Column(name="reader_count")
    private Long readerCount=0L;

    @Override
    public Long getId() {
        return id;
    }

    public Notice(long id, String title, Date createTime, Date updateTime, Boolean published,Date publishedTime,String publishedCode,Long readerCount) {
        this.id = id;
        this.title = title;
        this.setCreateTime(createTime);
        this.setUpdateTime(updateTime);
        this.published=published;
        this.publishedCode=publishedCode;
        this.publishedTime=publishedTime;
        this.readerCount=readerCount;
    }
    @JsonSerialize(using= JsonDateSerializer.class)
    public Date getPublishedTime() {
        return publishedTime;
    }

    public Notice() {
        super();
    }
}
